package Section1_ClassDesign;

/**
 * @author 刘昱恺
 *
 */
public class FractionImpl implements Fraction {


    /**
     * 分数的分子,可以为任意整数
     */
    private int molecule;

    /**
     * 分数的分母，可以为任意整数
     */
    private int denominator;

    public FractionImpl() {
    }

    public FractionImpl(int molecule, int denominator) {
        this.molecule = molecule;
        this.denominator = denominator;
        simplest(molecule,denominator);
    }


    public int getMolecule() {
        return molecule;
    }

    public void setMolecule(int molecule) {
        this.molecule = molecule;
    }

    public int getDenominator() {
        return denominator;
    }

    public void setDenominator(int denominator) {
        this.denominator = denominator;
    }

    @Override
    public Fraction add(Fraction fraction) {

        return null;
    }
    @Override
    public Fraction minus(Fraction fraction) {
        return null;
    }

    @Override
    public Fraction mul(Fraction fraction) {
        return null;
    }

    @Override
    public Fraction divide(Fraction fraction) {
        return null;
    }

    @Override
    public Fraction reverse() {
        return null;
    }

    @Override
    public boolean isBigger(Fraction fraction) {
        return false;
    }

    @Override
    public boolean equals(Fraction fraction) {
        return false;
    }

    @Override

    public void simplest(int integerOne, int integerTwo) {
        if(denominator != 0){
            int commonDivisor = getCommonDivisor(Math.abs(molecule), Math.abs(denominator));
            this.denominator = this.denominator / commonDivisor;
            this.molecule = this.molecule / commonDivisor;
        }else {

        }
    }

    @Override
    public String toString() {
        return molecule + "/" + denominator ;
    }

    /**
     * 获取两个正整数的最大公约数
     * @param integerOne 求公约数的除数
     * @param integerTwo 求公约数的被除数数
     * @return 求取到的最大公约数
     */
    private int getCommonDivisor(int integerOne,int integerTwo){
        while (integerTwo != 0){
            int temp = integerOne % integerTwo;
            integerOne = integerTwo;
            integerTwo = temp;
        }
        return integerOne;
    }
    public static void main(String[] args) {
        FractionImpl fraction = new FractionImpl(-4, -8);
        System.out.println("fraction = " + fraction);
    }
}

